#include <allegro.h>
#include <stdlib.h>
#include <unistd.h>
#include "chargement.h"
#include "collision.h"
#include "affichage.h"





void Affichage( perso p,ennem e, bon b,cartouche *c,vie *v , background bg , BITMAP *buffer , fleche *f )
{
	clear(buffer);
    draw_sprite(buffer, bg.back_ground,-p.ix/7,p.y/7 -130);
    draw_sprite(buffer, bg.background,bg.bh,300);

    if(f->posf==1 )
        {
              draw_sprite(buffer, f->img_f[f->pos] ,f->x ,f->y);
        }

    if(f->posf==-1)
        {
             draw_sprite(buffer, f->img_fl[f->pos] ,f->x ,f->y);
        }

       if(!key[KEY_S])
        {
            v->nombre_de_puissance=0;
        }

       if ( key[KEY_D]&& !key[KEY_RIGHT]&&!key[KEY_LEFT]  )
        {
                               if (  p.pos ==1  )
                                                {
                                                     draw_sprite(buffer,p.img_attack_r  ,p.x,p.y );
                                                }

                               if (  p.pos ==-1 )
                                                {
                                                     draw_sprite(buffer,p.img_attack_l  ,p.x,p.y );
                                                }
        }

       else
        if ( key[KEY_S] && !key[KEY_RIGHT]&&!key[KEY_LEFT]  )
                                {

                               draw_sprite(buffer,v->img_puiss[v->nombre_de_puissance%50/10],50,400);
                               if (  p.pos ==1  )
                                                {
                                                    draw_sprite(buffer,p.sans_flecher  ,p.x,p.y );
                                                }

                               if (  p.pos ==-1 )
                                            {
                                        draw_sprite(buffer,p.sans_flechel  ,p.x,p.y );
                                            }
                                }
     else
      if ( p.pos_jump ==2 )
                            {
                                draw_sprite(buffer,p.jumpr  ,p.x,p.y );
                            }
    else
     if ( p.pos_jump ==1 )
            {
                draw_sprite(buffer,p.jumpl  ,p.x,p.y );
            }
     else
        if (  p.pos ==1  )
    {
	draw_sprite(buffer,p.img_right[p.i%21/7]  ,p.x,p.y );
	}
	else
	if ( p.pos ==-1 )
    {
	draw_sprite(buffer,p.img_left[p.j%21/7]  ,p.x,p.y );
	}
     if (e.pos ==1  )
    {
	draw_sprite(buffer,e.img_right[e.j%15/5]  ,e.x,e.y );
	}
	if ( e.pos ==-1 )
    {
	draw_sprite(buffer,e.img_left[e.i%15/5]  ,e.x,e.y );
	}
    if (c->xx==1)
        {   c->x=c->x+5;
            c->xxx=c->xxx+5 ;
            c->y=c->y+c->dis ;
            draw_sprite(buffer,c->img_cart ,c->x,c->y );
        }

    if (c->xx==-1)
        {
            c->x=c->x-5;
            c->xxx=c->xxx+5;
            c->y=c->y-c->dis ;
            draw_sprite(buffer,c->img_cart ,c->x,c->y );
        }

	draw_sprite(buffer,v->img_vie[v->pourcentage]  ,100,100 );
	if ( v->pourcentage == 0 )
        {
            v->pourcentage=9 ;
            v->nobmre_de_vie  -- ;
        }
        if ( v->pourcentage == 10 )
        {
            v->pourcentage=1 ;
            v->nobmre_de_vie  ++ ;
        }

        draw_sprite(buffer,b.img_bonus  ,b.x,b.y );
//        draw_spric.te(buffer,bonus  ,b2.x,b2.y );
//          draw_spric.te(buffer,bonus  ,b3.x,b3.y );
        if ( v->nobmre_de_vie  ==0 )
        {
         textprintf_centre_ex(buffer, font, 400,50,makecol(255, 0 ,0), -1,"dsl vous aver perdu");
        }
        textprintf_centre_ex(buffer, font, 750,50,makecol(255, 0 ,0), -1,"nobmre_de_vie  : %d",v->nobmre_de_vie );


	blit(buffer,screen,0,0,0,0,1300,700);
}

